-
Notifications
You must be signed in to change notification settings - Fork 569
feat: add instrumentation to embedding functions for various backends #5120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add instrumentation to embedding functions for various backends #5120
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5120 +/- ##
==========================================
+ Coverage 83.95% 84.01% +0.06%
==========================================
Files 180 180
Lines 18077 18168 +91
Branches 3215 3227 +12
==========================================
+ Hits 15176 15264 +88
+ Misses 1919 1916 -3
- Partials 982 988 +6
|
### Description Regenerating tox because we need to update the config for the langchain test suite in #5120 and I don't want to pull in lots of unrelated changes on the feature branch. Dramatiq 2.0 has been released and our tests fail on it. Excluding it for now, we will follow up in #5123. #### Issues <!-- * resolves: #1234 * resolves: LIN-1234 --> #### Reminders - Please add tests to validate your changes, and lint your code using `tox -e linters`. - Add GH Issue ID _&_ Linear ID (if applicable) - PR title should use [conventional commit](https://develop.sentry.dev/engineering-practices/commit-messages/#type) style (`feat:`, `fix:`, `ref:`, `meta:`) - For external contributors: [CONTRIBUTING.md](https://github.com/getsentry/sentry-python/blob/master/CONTRIBUTING.md), [Sentry SDK development docs](https://develop.sentry.dev/sdk/), [Discord community](https://discord.gg/Ww9hbqr)
| if hasattr(provider_class, "aembed_query"): | ||
| provider_class.aembed_query = _wrap_async_embedding_method( | ||
| provider_class.aembed_query | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Missing guard against double-wrapping embedding methods
The _patch_embeddings_provider function lacks a guard to prevent double-wrapping when setup_once is called multiple times. Each call wraps the methods again, creating nested wrappers that can cause incorrect behavior. Other integrations like Celery, Huey, and Beam use a _sentry_is_patched flag to prevent this issue. The tests explicitly call setup_once multiple times, which triggers this bug.
Description
Wrap the backends OpenAIEmbeddings, AzureOpenAIEmbeddings, VertexAIEmbeddings, BedrockEmbeddings, CohereEmbeddings, MistralAIEmbeddings, HuggingFaceEmbeddings, OllamaEmbeddings and their embed_documents, embed_query, aembed_documents, aembed_query methods to properly instrument embeddings
Issues
Closes https://linear.app/getsentry/issue/TET-1460/add-embedding-support-for-langchain
Reminders
tox -e linters.feat:,fix:,ref:,meta:)